version: "3.7"

networks:
  backend-network:
    driver: bridge
    ipam:
      config:
        - subnet: 172.20.0.0/16
  frontend-network:
    driver: bridge
    ipam:
      config:
        - subnet: 172.30.0.0/16

services:
  postgres:
    container_name: lnpp-postgres-02
    build:
      context: ./postgres
      dockerfile: Dockerfile
    working_dir: /var/lib/postgres
    restart: unless-stopped
    ports:
      - "5432:5432"
    volumes:
      - ./storage/postgres:/var/lib/postgresql/data
      - ./logs/postgres:/var/log/postgresql
    networks:
      backend-network:
        ipv4_address: 172.20.0.2
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres

  php-fpm:
    container_name: lnpp-php-02
    build:
      context: ./php-fpm
      dockerfile: Dockerfile
    working_dir: /var/www
    restart: unless-stopped
    ports:
      - "9000:9000"
    expose:
      - "9003"
    volumes:
      - ../:/var/www
    extra_hosts:
      - "host.docker.internal:host-gateway"
    environment:
      - XDEBUG_MODE=develop,debug
    networks:
      backend-network:
        ipv4_address: 172.20.0.3
    depends_on:
      - postgres

  nginx:
    container_name: lnpp-nginx-02
    build:
      context: ./nginx
      dockerfile: Dockerfile
    working_dir: /var/www
    restart: unless-stopped
    ports:
      - "81:81"
      - "82:82"
    volumes:
      - ../:/var/www
      - ./logs/nginx:/var/log/nginx
    networks:
      frontend-network:
        aliases:
          - corebg.test
        ipv4_address: 172.30.0.2
      backend-network:
        aliases:
          - coreapi.test
        ipv4_address: 172.20.0.4
    depends_on:
      - postgres
      - php-fpm
